//
// Created by zhupi on 2024/9/5.
//

#include "gallery/base_cell/gallery_base_cell_widget.h"
#include <QFrame>
#include <QVBoxLayout>




GalleryBaseCellWidget::GalleryBaseCellWidget(QWidget *parent) {


    this->setFixedHeight(80);
    mainHbox_ = new QHBoxLayout;
    mainHbox_->setContentsMargins(0,0,0,0);
    widgetVbox_ = new QGridLayout;

    // 创建一个 QFrame，用来作为分割线
    QFrame *line = new QFrame(this);
    line->setFrameShape(QFrame::VLine);   // 设置为垂直线
    line->setFrameShadow(QFrame::Sunken); // 设置线的阴影样式
    line->setLineWidth(1);                // 设置线条宽度

    // 创建布局并添加控件
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(line);

    // 将布局设置到窗口中
    mainHbox_->addLayout(widgetVbox_);
    mainHbox_->addLayout(layout);
    mainHbox_->addStretch();
    this->setLayout(mainHbox_);
}

void GalleryBaseCellWidget::AddLargeAction(QAction *action) {

//    void addWidget(QWidget *, int row, int column, Qt::Alignment = Qt::Alignment());
//    void addWidget(QWidget *, int row, int column, int rowSpan, int columnSpan, Qt::Alignment = Qt::Alignment());
//    void addLayout(QLayout *, int row, int column, Qt::Alignment = Qt::Alignment());
//    void addLayout(QLayout *, int row, int column, int rowSpan, int columnSpan, Qt::Alignment = Qt::Alignment());
//    QWidget *widget = new QWidget(this);
//    widget->addAction(action);

    PToolButton *button = new PToolButton;
    button->setFixedSize(80,80);
    button->setIcon(action->icon());
    button->setIconSize(button->size());
    widgetVbox_->addWidget(button,  rowIndex_, columnindex_, 3, 1);

//    columnindex_ += 4;
    columnindex_ += 1;
    setStyleSheet("QWidget { background-color: gray; }");
}

void GalleryBaseCellWidget::AddMediumAction(QAction *action) {
    QWidget *widget = new QWidget(this);
    widget->addAction(action);
    if (rowIndex_ >= 3) {
        rowIndex_ = 0;
        columnindex_ += 1;
    }
    widgetVbox_->addWidget(widget,  rowIndex_, columnindex_, 4, 4);

    rowIndex_ += 1;
    setStyleSheet("QWidget { background-color: gray; }");
}

void GalleryBaseCellWidget::AddSmallAction(QAction *action) {
    QWidget *widget = new QWidget(this);
    widget->addAction(action);
    if (columnindex_ > 8) {
        columnindex_ = 0;
        rowIndex_ += 1;
    }
    widgetVbox_->addWidget(widget,  rowIndex_, columnindex_, 1, 1);

    columnindex_ += 1;
    widget->setStyleSheet("QWidget { background-color: gray; }");
}
